//当前的文件和文件夹的父级id
var pId = "0";

var fileTypeDesc = {
	"doc": "img/icon3.png",
	"excel": "img/icon1.png",
	"ppt": "img/icon2.png",
	"dir": "img/wenjian.png"
}


var fileList = [{
		fileId: "1",
		fileName: "1.xml",
		fileType: "excel",
		pId: "0"
	},
	{
		fileId: "2",
		fileName: "2.doc",
		fileType: "doc",
		pId: "5"
	},
	{
		fileId: "3",
		fileName: "3.ppt",
		fileType: "ppt",
		pId: "5"
	},
	{
		fileId: "4",
		fileName: "4",
		fileType: "dir",
		pId: "0"
	},
	{
		fileId: "5",
		fileName: "坤坤",
		fileType: "dir",
		pId: "0"
	},
]

function showFileList() {
	let s = "";
	for (f of fileList) {
		if (f.pId == pId) {
			s += `
				<div class="box" ondblclick="enterDir(${f.fileId})">
					<input type="checkbox" name="" id="">
					<br />
					<img src="${fileTypeDesc[f.fileType]}" alt="">
					<br />
					<span>${f.fileName}</span>
				</div>
			`
							
		}
	}
	let contain = document.getElementById("contain");
	contain.innerHTML = s;
}

showFileList();

function enterDir(fileId) {
	// alert("双击")
	console.log(fileId);
	console.log(typeof pId);
	console.log(typeof fileId);
	pId = fileId;
	showFileList();
}

function showAddWin() {
	document.getElementById("win").style.display = "block";
}

function closeWin(){
	document.getElementById("win").style.display = "none";
}

function addFile(){
	let fileName = document.getElementById("fileName").value.trim();
	let fileType = document.getElementById("fileType").value.trim();
	console.log(fileName,fileType);
	let f = {
		fileId:new Date().getTime(),
		fileName:fileName,
		fileType:fileType,
		pId:pId
	}
	fileList.push(f);
	showFileList();
	closeWin();
}

function backDir(){
	for(f of fileList){
		if(f.fileId == pId){
			pId = f.pId;
			break;
		}
	}
	showFileList();
}